package com.itheima.controller;

import cn.hutool.core.convert.Convert;
import com.itheima.R;
import com.itheima.dto.CreateCouponDto;
import com.itheima.pojo.SmsFlashPromotion;
import com.itheima.pojo.SmsFlashPromotionSession;
import com.itheima.service.FlashSessionService;
import com.itheima.vo.PageResult;
import com.itheima.vo.SmsFlashPromotionSessionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Hakuna Matata
 * @date 2022-10-13-10:24
 */
@RestController
@RequestMapping("flashSession")
public class FlashSessionController {

    @Autowired
    private FlashSessionService flashSessionService;

    //添加场次
    @PostMapping("create")
    public R flashPromotionCreate(@RequestBody SmsFlashPromotionSession flashPromotionSession) {
        flashSessionService.sessionCreate(flashPromotionSession);
        return R.success("场次增加成功!");
    }

    /**
     * 删除场次
     *
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    public R sessionDelete(@PathVariable("id") Long id) {
        flashSessionService.sessionDelete(id);
        return R.success("删除场次成功");
    }

    /**
     * 获取全部场次
     */
    @GetMapping("list")
    public R sessionList() {
        List<SmsFlashPromotionSession> list = flashSessionService.sessionList();
        return R.success(list);
    }

    //获取全部可选场次及其数量
    //id  ==> flashPromotionId
    @GetMapping("selectList")
    public R sessionSelectList(Long flashPromotionId) {
        List<SmsFlashPromotionSessionVo> list = flashSessionService.sessionSelectList(flashPromotionId);
        return R.success(list);
    }

    //修改启用状态
    @PostMapping("/update/status/{id}")
    public R updateStatus(@PathVariable("id") Long id, Integer status) {
        flashSessionService.updateStatus(id, status);
        return R.success("操作成功");
    }

    //修改场次
    @PostMapping("update/{id}")
    public R sessionUpdate(@PathVariable("id") Integer id, @RequestBody SmsFlashPromotionSession flashPromotionSession) {
        flashSessionService.sessionUpdate(id, flashPromotionSession);
        return R.success("操作成功");
    }


    //获取场次详情
    @GetMapping("{id}")
    public R findSessionById(@PathVariable("id") Long id) {
        SmsFlashPromotionSession flashPromotionSession = flashSessionService.findSessionById(id);
        return R.success(flashPromotionSession);
    }
}
